package com.fita.wechat.dao;

import java.util.List;
import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.fita.entity.coupon.Coupon;
import com.fita.entity.coupon.CouponStatus;
import com.fita.entity.order.Order;

/**
 * 
 * @author dan
 *
 */
@Dao("hibernate")
public interface CouponDao {
    

    /**
     * LZJ
     * @param userId
     * @param couponStatus
     * @return
     */
    @Query("FROM Coupon WHERE userId = :userId  AND status in (1,2) AND template.minAmount < :cnyPayPrice")
    public List<Coupon> listUserAllAvailableCoupons(@Variable("userId")Long userId,
    												@Variable("cnyPayPrice")Integer cnyPayPrice);
    

    @Query("FROM Coupon WHERE order = :order")
    public List<Coupon> listCouponsByOrder(@Variable("order")Order order);
    
    @Query("FROM Coupon WHERE userId = :userId")
    public List<Coupon> listUserAllCoupons(@Variable("userId")Long userId);


    @Limit
    @Query("FROM Coupon WHERE status = :status  and template.id = :templateId")
    public List<Coupon> loadManyCoupon(@Variable("status") CouponStatus status, @Variable("templateId") Long templateId, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);


    @Query("FROM Coupon WHERE status = :status  and template.id = :templateId")
    public Coupon loadSingleCoupon(@Variable("status") CouponStatus status,@Variable("templateId") Long templateId);


}
